﻿Imports System.Text

Public Class Form1
    Private App As New lfm.Application() With {.ApiKey = "7078bfb95ae97bf1a13ffe78a572cd3d",
                                               .AppSecret = "3a8471d48d3e3c63cfcee619a026f218"}
    Private UserSession As lfm.UserInfo
    Private Rest As New lfm.REST(App)
    Dim listener As TextWriterTraceListener
    Dim stringWriter As IO.StringWriter
    Dim stringBuild As New StringBuilder
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        StringWriter = New IO.StringWriter(stringBuild)
        Listener = New TextWriterTraceListener(StringWriter)
        Debug.Listeners.Add(Listener)
        debugTimer.Start()

        textDebug.HideSelection = True
        textDebug.ReadOnly = True
    End Sub

    Private Sub debugTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles debugTimer.Tick
        textDebug.Text = stringBuild.ToString
        If textDebug.Text.Length > 4 Then
            textDebug.SelectionStart = textDebug.Text.Length - 3
            textDebug.SelectionLength = 2
            textDebug.ScrollToCaret()
        End If
    End Sub

    Private Sub buttonTokenAuth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonTokenAuth.Click
        labelTokenAuth.Text = Rest.Auth.getToken
    End Sub

    Private Sub buttonMobileAuthLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonMobileAuthLogin.Click
        UserSession = Rest.Auth.getMobileSession(textMobileAuthUsername.Text, textMobileAuthPassword.Text)
    End Sub

    Private Sub textMobileAuthPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textMobileAuthPassword.TextChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If Me.UserSession Is Nothing Then Me.UserSession = New lfm.UserInfo
            Me.Rest.User.GetInfo(textInfoUserName.Text, Me.UserSession)
            Dim text As String = ""
            With Me.UserSession
                text += "User Id = " + .Id.ToString + vbCrLf
                'Public Property Id As Integer
                text += "Username = " + .Name.ToString + vbCrLf
                'Public Property Name As String
                text += "User real name = " + .Realname.ToString + vbCrLf
                'Public Property Realname As String
                text += "User Url = " + .Url.ToString + vbCrLf
                'Public Property Url As Uri
                text += "User Age = " + .Age.ToString + vbCrLf
                'Public Property Age As Integer
                text += "User Image Url = " + .ImageUrl.ToString + vbCrLf
                pictureUserInfo.ImageLocation = .ImageUrl.ToString
                'Public Property ImageUrl As Uri
                text += "User CC = " + .CountryCode.ToString + vbCrLf
                'Public Property CountryCode As String
                text += "User Gender = " + .Sex.ToString + vbCrLf
                'Public Property Sex As Gender
                text += "User Subscriber = " + .Subscriber.ToString + vbCrLf
                'Public Property Subscriber As Boolean
                text += "User Playcount = " + .Playcount.ToString + vbCrLf
                'Public Property Playcount As Integer
                text += "User PlaylistCount = " + .PlaylistCount.ToString + vbCrLf
                'Public Property PlaylistCount As Integer
                text += "User Bootstrap = " + .Bootstrap.ToString + vbCrLf
                'Public Property Bootstrap As Boolean
                text += "User RegisterTime = " + .RegisterTime.ToString + vbCrLf
                'Public Property RegisterTime As Date
            End With
            textInfoUser.Text = text
        Catch ex As Exception
            textInfoUser.Text += vbCrLf + vbCrLf + ex.ToString
        End Try
    End Sub
End Class
